package com.woniuxy.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.daos.DevelopmentplanDao;
import com.woniuxy.entitys.Developmentplan;
import com.woniuxy.services.DevelopmentplanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class DevelopmentplanServiceImpl implements DevelopmentplanService {
    @Autowired
    private DevelopmentplanDao developmentplanDao;
    @Override
    public PageInfo<Developmentplan> selalldevp(String key, Integer pagenow, Integer pagesize, String startDate, String overDate) {
        PageHelper.startPage(pagenow,pagesize);
        List<Developmentplan> list=developmentplanDao.selectalldevp(startDate,overDate,key);
        //if(key.equals("")&&startDate.equals("")&&overDate.equals("")) {
            for (Developmentplan developmentplan : list
            ) {
                List<Developmentplan> list1 = developmentplanDao.selalldevpbysaleid1(developmentplan.getSale_id().toString());
                developmentplan.setChildren(list1);
            }
       // }
        return new PageInfo(list);
    }




    public List<Developmentplan> getchilddevp(Developmentplan developmentplan){
        List<Developmentplan> list=new ArrayList<>();

        return  list;
    }

    @Override
    public PageInfo<Developmentplan> selalldevpbysaleid(String sale_id) {

        return new PageInfo(developmentplanDao.selalldevpbysaleid(sale_id));
    }

    @Override
    public int changestatus(String dp_id) {
        return developmentplanDao.changestatus(dp_id);
    }

    @Override
    public int updatedevp(Developmentplan developmentplan) {
        return developmentplanDao.updateByPrimaryKeySelective(developmentplan);
    }

    @Override
    public int adddevp(Developmentplan developmentplan) {
        return developmentplanDao.insertSelective(developmentplan);
    }

    @Override
    public int delalldevps(String[] ids) {
        return developmentplanDao.delealldevp(ids);
    }

    @Override
    public int updatedevpdtatu(String sale_id, String status) {
        return developmentplanDao.updatedevpstatus(sale_id,status);
    }

    @Override
    public PageInfo<Developmentplan> selalldevp1(String key, Integer pagenow, Integer pagesize, String startDate, String overDate, String user_code) {
        PageHelper.startPage(pagenow,pagesize);
        List<Developmentplan> list=developmentplanDao.selectalldevp1(startDate,overDate,key,user_code);
       // if(key.equals("")&&startDate.equals("")&&overDate.equals("")){
            for (Developmentplan developmentplan:list
            ) {
                List<Developmentplan> list1=developmentplanDao.selalldevpbysaleid1(developmentplan.getSale_id().toString());
                developmentplan.setChildren(list1);
            }
       // }
        return new PageInfo(list);

    }
}
